﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CSMSys.Lib.Manager.Reports;
namespace CSMSys.Web.Reports
{
    public partial class Service : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                grvservice.DataBind();
            }
        }
        protected void imgRefresh_Click(object sender, EventArgs e)
        {
            grvservice.DataBind();
        }
        protected void imgSearch_Click(object sender, ImageClickEventArgs e)
        {
            //strSearch = txtSearch.Text.Trim();
        }
        #region Methods For Grid
        protected void grvservice_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            //if (e.CommandName.Equals("Delete"))
            //{
            //    int intPartyID = Convert.ToInt32(e.CommandArgument.ToString());

            //    if (intPartyID > 0)
            //    {
            //        DeleteParty(intPartyID);
            //    }
            //}
        }

        protected void grvservice_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            grvservice.PageIndex = e.NewPageIndex;
            grvservice.DataBind();
        }

        protected void grvservice_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if ((e.Row.RowType == DataControlRowType.DataRow) && (e.Row.Cells[1].Controls.Count > 0))
            {
                SqlDataSource dssStock = (SqlDataSource)e.Row.FindControl("dssStock");
                dssStock.SelectCommand =
                    @"SELECT ss.SerialNo,reg.BagLoan,reg.CarryingLoan,ss.SerialId,reg.RegistrationID  
                    from INVStockSerial as ss 
                    left JOIN SRVRegistration as reg on reg.serialNo = ss.SerialNo 
                    where PartyCode='" +(DataBinder.Eval(e.Row.DataItem,"partycode"))+"'";
                
            }
        }

        protected void grvserials_rowbound(object sender, GridViewRowEventArgs e)
        {
            if ((e.Row.RowType == DataControlRowType.DataRow) && (e.Row.Cells[1].Controls.Count > 0))
            {
                if (DataBinder.Eval(e.Row.DataItem, "registrationID")==DBNull.Value)
                {
                    ((Label) e.Row.FindControl("lblloandisbursed")).Text = "Not Disbursed";
                }
                else
                {
                    ((Label) e.Row.FindControl("lblloandisbursed")).Text =
                        new ServiceReportManager().retLoanDisbursed(
                            Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "serialID"))).ToString();
                }
            }
        }

        
        #endregion
    }
}